<?php

/*
 * - Okek CMS
 * - create by Jg and Tito
 * - Okek Projects 2012
 * - CMS developed for free use
 * - More info http://habbo-dev.com
 */

class Users
{
    public function getSession() {
        
        global $userdata;
        
        $user = $_SESSION['habbo']['email'];
        $password = $_SESSION['habbo']['password'];
        
        if(isset($user) && isset($password)) {
            if($this->CheckLogin($user, $password)) {
                
                if(!isset($_SESSION['habbo']['data']) || !$_SESSION['habbo']['data']) {
                    $_SESSION['habbo']['data'] = $this->getData($user);
                }
                
                define('LOGGED_IN', true);
                $userdata = $_SESSION['habbo']['data'];
            }
            else {
                goto error;
            }
        }
        else {
            goto error;
        }
        
        error: {
            define('LOGGED_IN', false);
            $userdata = null;
        }
    }
    
    public function getData($user) {
        $query = query("SELECT * FROM users WHERE email = '".$user."' AND last_session = '1' LIMIT 1");
        return mysql_fetch_assoc($query);
    }
    
    public function CheckLogin($username, $password){
        global $site;
        $exists = query_rows("SELECT * FROM users WHERE email = '".$username."' AND password = '".$site->SecurePass($password)."' AND last_session = '1' LIMIT 1");
        return ($exists > 0 ? true : false);
    }
    
    public function onlineUsers() {
        return 0;
    }
}
?>
